<?php
/**
 * Created by PhpStorm.
 * User: llc
 * Date: 17-3-1
 * Time: 上午9:53
 */

namespace app\backend\model;

use think\Model;

class PingAnModel extends model
{
    private $pingAnTable     = 'z_pingan_order';
    public function __construct() {
        parent::__construct();
    }

    /**
     * 添加平安银行订单记录
     * @date   2017-02-14
     * @author Lanlc
     *
     * @param  string  $mid          用户ID
     * @param  string  $orderNum     租户通订单号
     * @param  string  $pingAnOrder  平安银行订单号
     * @param  int     $type         租户通订单类型：1租赁，2托管
     * @param  int     $beginCycle   账单起始周期
     * @param  int     $endCycle     账单结束周期
     *
     * @return
     */
    public function setOrder($mid, $orderNum, $pingAnOrder, $type, $beginCycle, $endCycle)
    {
        $data = [
            'mid'          => $mid,
            'ordernum'     => $orderNum,
            'pingan_order' => $pingAnOrder,
            'type'         => $type,
            'begin_cycle'  => $beginCycle,
            'end_cycle'    => $endCycle,
        ];
        $res = $this->setTable($this->pingAnTable)->insertGetId($data);
        return $res ? $res : false;
    }

    /**
     * 通过平安的订单号获取租户通订单信息
     * @date   2017-02-14
     * @author Lanlc
     *
     * @param  string  $pingAnOrder  平安银行订单号
     * @param  int     $type         租户通订单类型：1租赁，2托管
     *
     * @return
     */
    public function getOrderNum($pingAnOrder, $type)
    {
        $where = [
            'pingan_order' => $pingAnOrder,
            'type'         => $type,
        ];

        $field = 'mid, ordernum, begin_cycle, end_cycle';

        $res = $this->setTable($this->pingAnTable)->field($field)->where($where)->find();
        return $res ? $res : false;
    }
}
